package controller.member;

import model.MUser;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import common.interf.IErrorHandle;

import service.interf.IUser;

@Controller
@RequestMapping("/user")
public class MemberEditController {

	@Autowired
	private IUser user;
	@Autowired
	private IErrorHandle errorHandle;
	
	@RequestMapping("/add_user.htm")
	@ResponseBody
	public String addUser(MUser model) {
	    String s = "";
	    try {
			s = user.addUser(model);
		} catch (Exception e) {
			System.out.println("methods : editUser");
			errorHandle.handleErr(e);
		}
		//debug pass
		return s;
	}
	
	
	@RequestMapping("/edit_user.htm")
	@ResponseBody
    public String editUser(MUser model) {
		String s = "";
		try {
			s = user.editUser(model);
		} catch (Exception e) {
			System.out.println("methods : editUser");
			errorHandle.handleErr(e);
		}
		//debug pass
		return s;
	}
	
	@RequestMapping("/del_user.htm")
	@ResponseBody
	public String delUser(MUser model) {
		String s = "";
		try {
			s = user.delUser(model.getUserId());
		} catch (Exception e) {
			System.out.println("methods : delUser");
			errorHandle.handleErr(e);
		}
		//debug pass
		return s;
	}
	
	// 使能用户(根据id)
	@RequestMapping("/enable_userById.htm")
	@ResponseBody
	public String enableUserById(MUser model) {
		String s = "";
		try {
			s = user.enableUser(model.getUserId(), model.getEnabled());
		} catch (Exception e) {
			System.out.println("methods : enabelUser");
			errorHandle.handleErr(e);
		}
		return s;
	}

	// 使能用户（根据用户名
	//
	@RequestMapping("/enable_userByName.htm")
	@ResponseBody
	public String enableUserByName(MUser model) {
		String s = "";
		try {
			s = user.enableUser(model.getUserName(), model.getEnabled());
		} catch (Exception e) {
			System.out.println("methods : enabelUser");
			errorHandle.handleErr(e);
		}
		return s;
	}

	
	
}
